package com.hsav.kcxb.fragment.my;

import android.content.Intent;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.hsav.kcxb.R;
import com.hsav.kcxb.activity.OtherUserCenterActivity;
import com.hsav.kcxb.activity.UserCenterActivity;
import com.hsav.kcxb.adapter.UserItemAdapter;
import com.hsav.kcxb.bean.UsertItemBean;
import com.hsav.kcxb.utils.MySpaceDesc;

/**
 * Created by zhao on 2017/1/8.
 */

public class MyFrinendFavFragment extends Fragment {

    private ListView mListView;
    private RecyclerView mRecyclerView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.frg_friend_fav_layout,container,false);
        initView(rootView);
        return rootView;
    }

    private void initView(View rootView) {
        mRecyclerView = (RecyclerView)rootView.findViewById(R.id.recycler_view);
        UserItemAdapter itemAdapter = new UserItemAdapter(getContext(),null);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
        mRecyclerView.setLayoutManager(linearLayoutManager);
//        mRecyclerView.addItemDecoration(new UserItemAdapter.SpaceItem(20));
        mRecyclerView.addItemDecoration(new MySpaceDesc() {
            @Override
            protected void handleOffSet(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
                int pos = parent.getChildAdapterPosition(view);
                if(pos == 0){
                    outRect.top = 50;
                }
                outRect.bottom = 50;
            }
        });
        itemAdapter.setOnHandleClickListener(new UserItemAdapter.OnHanldeClickListener() {
            @Override
            public void handleClick(UsertItemBean itemBean, int type) {
                Intent intent = new Intent();
                if(UserItemAdapter.TYPE_MY_CENTER == type){
                    intent.setClass(getContext(), UserCenterActivity.class);
                }else if(UserItemAdapter.TYPE_OTHER_CENTER == type){
                    intent.setClass(getContext(), OtherUserCenterActivity.class);
                }
                startActivity(intent);
            }
        });

        mRecyclerView.setAdapter(itemAdapter);

    }
}
